﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib"
                    xmlns:s="clr-namespace:MockupDesigner.AppItems"
                    xmlns:c="clr-namespace:MockupDesigner.AppItems.Controls"
                    xmlns:cmd="clr-namespace:MockupDesigner.AppItems.Commands"
                    xmlns:w="clr-namespace:MockupDesigner"
    >

    <ContextMenu x:Key="DesignerCanvasContextMenu">
        <MenuItem Header="Paste" Command="{x:Static ApplicationCommands.Paste}">
            <MenuItem.Icon>
                <Image Source="Images/Paste.png" Width="16"/>
            </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="Select All" Command="{x:Static cmd:MDCommands.SelectAll}"/>
    </ContextMenu>

    <ContextMenu x:Key="DesignerItemContextMenu">
        <MenuItem Header="Cut" Command="{x:Static ApplicationCommands.Cut}">
            <MenuItem.Icon>
                <Image Source="Images/Cut.png" Width="16"/>
            </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="Copy" Command="{x:Static ApplicationCommands.Copy}">
            <MenuItem.Icon>
                <Image Source="Images/Copy.png" Width="16"/>
            </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="Paste" Command="{x:Static ApplicationCommands.Paste}">
            <MenuItem.Icon>
                <Image Source="Images/Paste.png" Width="16"/>
            </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="Delete" Command="{x:Static ApplicationCommands.Delete}">
            <MenuItem.Icon>
                <Image Source="Images/Delete.png" Width="16"/>
            </MenuItem.Icon>
        </MenuItem>
        <Separator/>
        <MenuItem Header="Grouping">
            <MenuItem Header="Group" Command="{x:Static cmd:MDCommands.Group}">
                <MenuItem.Icon>
                    <Image Source="Images/Group.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Ungroup" Command="{x:Static cmd:MDCommands.Ungroup}">
                <MenuItem.Icon>
                    <Image Source="Images/Ungroup.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
        </MenuItem>
        <MenuItem Header="Order">
            <MenuItem Header="Bring Forward" Command="{x:Static cmd:MDCommands.BringForward}">
                <MenuItem.Icon>
                    <Image Source="Images/BringForward.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Bring To Front" Command="{x:Static cmd:MDCommands.BringToFront}">
                <MenuItem.Icon>
                    <Image Source="Images/BringToFront.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Send Backward" Command="{x:Static cmd:MDCommands.SendBackward}">
                <MenuItem.Icon>
                    <Image Source="Images/SendBackward.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Header="Send To Back" Command="{x:Static cmd:MDCommands.SendToBack}">
                <MenuItem.Icon>
                    <Image Source="Images/SendToBack.png" Width="16"/>
                </MenuItem.Icon>
            </MenuItem>
        </MenuItem>
        <MenuItem Header="Add To Custom Controls" Command="{x:Static cmd:MDCommands.AddToCustomControls}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type s:DesignerItem}}}"/>
    </ContextMenu>

    <!-- ResizeDecorator Default Template -->
    <ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}">
        <Grid SnapsToDevicePixels="false">
            <Rectangle Fill="Black" Opacity="0.3"
                       Height="{Binding RelativeSource={RelativeSource Self}, Path=Height}"                       
                       Width="{Binding RelativeSource={RelativeSource Self}, Path=Width}"/>                       
            <c:ResizeThumb Height="2" BorderBrush="Black" BorderThickness="1" Cursor="SizeNS" Margin="0 0 0 0"
                     VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
            <c:ResizeThumb Width="2" BorderBrush="Black" BorderThickness="1" Cursor="SizeWE" Margin="0 0 0 0"
                     VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
            <c:ResizeThumb Width="2" BorderBrush="Black" BorderThickness="1" Cursor="SizeWE" Margin="0 0 0 0"
                     VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
            <c:ResizeThumb Height="2" BorderBrush="Black" BorderThickness="1" Cursor="SizeNS" Margin="0 0 0 0"
                     VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
            <c:ResizeThumb Width="5" Height="5" BorderBrush="Black" BorderThickness="1" Cursor="SizeNWSE" Margin="-2 -2 0 0"
                     VerticalAlignment="Top" HorizontalAlignment="Left"/>
            <c:ResizeThumb Width="5" Height="5" BorderBrush="Black" BorderThickness="1" Cursor="SizeNESW" Margin="0 -2 -2 0"
                     VerticalAlignment="Top" HorizontalAlignment="Right"/>
            <c:ResizeThumb Width="5" Height="5" BorderBrush="Black" BorderThickness="1" Cursor="SizeNESW" Margin="-2 0 0 -2"
                     VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
            <c:ResizeThumb Width="5" Height="5" BorderBrush="Black" BorderThickness="1" Cursor="SizeNWSE" Margin="0 0 -2 -2"
                     VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
        </Grid>
    </ControlTemplate>

    <!-- DragThumb Default Template -->
    <Style TargetType="{x:Type c:DragThumb}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type c:DragThumb}">
                    <Rectangle Fill="Transparent" Margin="1 1 1 1"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- DesignerItem Style -->
    <Style TargetType="{x:Type s:DesignerItem}">
        <Setter Property="MinWidth" Value="10"/>
        <Setter Property="MinHeight" Value="10"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type s:DesignerItem}">
                    <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                        <!-- PART_ContentPresenter -->
                        <ContentPresenter x:Name="PART_ContentPresenter" IsHitTestVisible="false"
                                          HorizontalAlignment="Stretch"
                                          VerticalAlignment="Stretch"
                                          Content="{TemplateBinding ContentControl.Content}"
                                          Margin="{TemplateBinding ContentControl.Padding}"/>
                        <!-- PART_ResizeDecorator -->
                        <Control x:Name="PART_ResizeDecorator" 
                                 Visibility="Collapsed"
                                 Template="{StaticResource ResizeDecoratorTemplate}" />
                        <!-- PART_DragThumb -->
                        <c:DragThumb x:Name="PART_DragThumb" Cursor="SizeAll" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <DataTrigger Value="True" Binding="{Binding RelativeSource={RelativeSource Self},Path=IsInToolbox}">
                            <Setter TargetName="PART_DragThumb" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Value="True" Binding="{Binding RelativeSource={RelativeSource Self},Path=IsSelected}"/>
                                <Condition Value="{x:Static sys:Guid.Empty}" Binding="{Binding RelativeSource={RelativeSource Self},Path=ParentID}"/>
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="PART_ResizeDecorator" Property="Visibility" Value="Visible"/>
                        </MultiDataTrigger>
                        <Trigger Property="IsInToolbox" Value="false">
                            <Setter Property="ContextMenu" Value="{StaticResource DesignerItemContextMenu}"/>
                        </Trigger>
                        <Trigger Property="IsInToolbox" Value="true">
                            <Setter Property="ContextMenu" Value="{x:Null}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>